package com.example.takeaway.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.example.takeaway.entity.Orderdetail;
import com.example.takeaway.serivce.IOrderdetailService;
import com.example.takeaway.utils.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * orderdetailController
 * 
 * @author ruoyi
 * @date 2025-05-15
 */
@RestController
@RequestMapping("/system/orderdetail")
public class OrderdetailController{
    @Autowired
    private IOrderdetailService orderdetailService;

    /**
     * 查询orderdetail列表
     */
//    @PreAuthorize("@ss.hasPermi('system:orderdetail:list')")
    @GetMapping("/list")
    public ServerResponse list(Orderdetail orderdetail)
    {
//        startPage();
        List<Orderdetail> list = orderdetailService.selectOrderdetailList(orderdetail);
//        return getDataTable(list);
        return  ServerResponse.createBysuccess(200,list,"查询成功");
    }

    /**
     * 导出orderdetail列表
     */
//    @PreAuthorize("@ss.hasPermi('system:orderdetail:export')")
//    @Log(title = "orderdetail", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Orderdetail orderdetail)
//    {
//        List<Orderdetail> list = orderdetailService.selectOrderdetailList(orderdetail);
//        ExcelUtil<Orderdetail> util = new ExcelUtil<Orderdetail>(Orderdetail.class);
//        util.exportExcel(response, list, "orderdetail数据");
//    }

    /**
     * 获取orderdetail详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:orderdetail:query')")
    @GetMapping(value = "/{detailid}")
    public ServerResponse getInfo(@PathVariable("detailid") Long detailid)
    {
        Orderdetail orderdetail = orderdetailService.selectOrderdetailByDetailid(detailid);
        return ServerResponse.createBysuccess(200,orderdetail,"查询成功");
    }

    /**
     * 新增orderdetail
     */
//    @PreAuthorize("@ss.hasPermi('system:orderdetail:add')")
//    @Log(title = "orderdetail", businessType = BusinessType.INSERT)
    @PostMapping
    public ServerResponse add(@RequestBody Orderdetail orderdetail)
    {

        int i = orderdetailService.insertOrderdetail(orderdetail);
        if (i>0){
            return  ServerResponse.createBysuccess(200,"","新增成功");
        }else{
            return  ServerResponse.createByfail(400,"新增失败");
        }

    }

    /**
     * 修改orderdetail
     */
//    @PreAuthorize("@ss.hasPermi('system:orderdetail:edit')")
//    @Log(title = "orderdetail", businessType = BusinessType.UPDATE)
    @PutMapping
    public ServerResponse edit(@RequestBody Orderdetail orderdetail)
    {
       int i = orderdetailService.updateOrderdetail(orderdetail);
        if (i>0){
            return  ServerResponse.createBysuccess(200,"","新增成功");
        }else{
            return  ServerResponse.createByfail(400,"新增失败");
        }
    }

    /**
     * 删除orderdetail
     */
//    @PreAuthorize("@ss.hasPermi('system:orderdetail:remove')")
//    @Log(title = "orderdetail", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailids}")
    public ServerResponse remove(@PathVariable Long[] detailids)
    {
       int i = orderdetailService.deleteOrderdetailByDetailids(detailids);
        if (i>0){
            return  ServerResponse.createBysuccess(200,"","新增成功");
        }else{
            return  ServerResponse.createByfail(400,"新增失败");
        }
    }
}
